#include "sdk_model_generic.h"
#include "sdk_proto.h"
#include  "sdk.h"
#include <stdio.h>
#include <string.h>





int sdk_model_generic_onoff(uint16_t addr,uint8_t onoff,uint8_t swidx)
{
    char json[1024]={0};
    char ctldata[100]={0};
    uint16_t attrid = 0;
    if(addr==0){
        sdk_printf("%s:addr==0",__FUNCTION__);
        return SDK_PARAMS_ERR;
    }
    
    //D1F9096F002000FF
    sprintf(ctldata,"%02x%02x",onoff,swidx);
    attrid = SDK_MODEL_GENERIC_CTL_ATTRID;

    sprintf(json,"{\"call\":\"ai.argrace.gw.data.set\",\"ak\":\"%s\",\"gwid\":%u,\"ad\":\"%04x\",\"op\":\"%s\",\"vma\":\"%02x%02x\",\"data\":\"%s\",\"tid\":\"%02x\",\"mac\":\"%s\"}",\
        sdk_proto_context_get()->accesskey,sdk_proto_context_get()->gwid,addr,VMAD1,attrid&0xFF,(attrid>>8)&0xFF,ctldata,sdk_proto_get_tid(),sdk_context.mac);

    sdk_printf("%s:%s\r\n",__FUNCTION__,json);
    return sdk_proto_ctl_send((uint8_t *)json,strlen(json)+1);
}



int sdk_model_genneric_sence(unsigned short  addr,unsigned short  senceid)
{
    char json[500]={0};
    char ctldata[100]={0};
    uint16_t attrid = 0;

    if(addr==0){
        sdk_printf("%s:addr=0\r\n",__FUNCTION__);
        return SDK_PARAMS_ERR;
    }

    if(senceid==0){
        sdk_printf("%s:senceid=0\r\n",__FUNCTION__);
        return SDK_PARAMS_ERR;
    }

    //"D1F9092207108200000000"
    sprintf(ctldata,"%02x%02x%02x0000",0x82,senceid & 0xFF,(senceid >>8)& 0xFF);
    attrid = ATTRID1021HEX; 

    sprintf(json,"{\"call\":\"ai.argrace.gw.data.set\",\"ak\":\"%s\",\"gwid\":%u,\"ad\":\"%02x\",\"op\":\"%s\",\"vma\":\"%02x%02x\",\"data\":\"%s\",\"tid\":\"%02x\"}",\
        sdk_proto_context_get()->accesskey,sdk_proto_context_get()->gwid,addr,VMAD1,attrid&0xFF,(attrid>>8)&0xFF,ctldata,sdk_proto_get_tid());

    sdk_printf("%s:%s\r\n",__FUNCTION__,json);
    return sdk_proto_ctl_send((uint8_t *)json,strlen(json)+1);
}

